package com.tian.controller.management;

import com.tian.common.CommonResult;
import com.tian.dto.GenerateCodeReqDto;
import com.tian.service.ExchangeCodeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * {@code @description:} 兑换码控制器
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-11-13 9:44
 * {@code @version:} 1.0
 */
@RestController
@RequestMapping("/exchange/code")
@Api(tags = "兑换码 控制器")
public class ExchangeCodeController {
    @Resource
    private ExchangeCodeService exchangeCodeService;

    /**
     * 生成兑换码
     */
    @PostMapping("/generate")
    public CommonResult<Boolean> generateCode(@RequestBody GenerateCodeReqDto generateCodeReqDto) {
        return exchangeCodeService.generateCode(generateCodeReqDto.getCouponId(), generateCodeReqDto.getCount());
    }

    /**
     * 校验兑换码
     */
    @GetMapping("/validate/{code}")
    public CommonResult<Boolean> validateCode(@PathVariable("code") String code) {
        return exchangeCodeService.validateCode(code);
    }

}
